﻿using System;
using System.Net;
using System.Linq;
using System.Collections.Generic;

namespace Tulde.Windows.Music.Mp3Tunes
{
   
    public class LockerPlayerService : LockerStorageService
    {

        //public override Uri CreateServiceEndpoint(LockerStorageOperations operation, ServiceParameters parameters)
        //{
        //   // return new Uri(this.AppendParametersToUrl(this.BaseUrl, operation.ToString(), parameters));
        //    string url = String.Format(this.BaseUrl + "{0}", parameters["fileKey"]+"/");
        //    parameters.Remove("fileKey");
        //    return new Uri(this.AppendParametersToUrl(url, operation.ToString(), parameters));
            
        //}
        protected override string AppendParametersToUrl(string url, string operation, ServiceParameters parameters)
        {
            string fkey = parameters.Remove(Constants.FileKey);
           

            string x = "";

            if (parameters.Keys.Contains("ext"))
            {
                x = parameters.Remove("ext");
               
            }
           
            List<string> parametersList = new List<string>();
            foreach (string key in parameters.Keys)
            {
                parametersList.Add(String.Format("{0}={1}", key, parameters.GetParameter(key)));
            }
            if (parameters == null || !parameters.Keys.Any())
            {
                return url;
            }
            else
            {
                if( !String.IsNullOrEmpty(x))
                    parametersList.Add("ext=.mp3");
                return url + operation + "/"+fkey+ "?" + String.Join("&", parametersList.ToArray());
            }
        }
      
    }
}
